package com.yingda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.yingda.ad.R;


import java.util.List;

public class SwichAdapter extends RecyclerView.Adapter<SwichAdapter.ViewHolder> {

    private final Context context1;
    private final List<String> list;
    private ImageView iv_swich_item;
    private TextView tv_switch_item;
    private int currentPosition = 0;
    private Context context;
    private OnClickListener listener;


    public SwichAdapter(Context context, List<String> list) {

        context1 = context;
        this.list = list;
    }

    private View inflate(ViewGroup parent, int layoutRes) {
        return LayoutInflater.from(parent.getContext()).inflate(layoutRes, parent, false);
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        ViewHolder viewHolder = new ViewHolder(inflate(parent, R.layout.item_swich));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull  ViewHolder holder, int position) {
        holder.setIsRecyclable(false);
        String name = list.get(position);
        holder.tv_name.setText(name);

        holder.ll_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null){
                    listener.click(position);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }




    protected class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv_name;
        private final RelativeLayout ll_rl;

        public ViewHolder(@NonNull  View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            ll_rl = itemView.findViewById(R.id.ll_rl);
        }
    }


    public interface OnClickListener{
        void click(int pos);
    }

    public void setOnClickListener(OnClickListener listener){

        this.listener = listener;
    }
}
